
<form class="layui-form seller-form" action="" method="post">
    <div class="layui-form-item">
        <div class="layui-inline">
            <input type="text" name="username" lay-verify="title" style="width:200px;"
                 class="layui-input" placeholder="Username">
        </div>
        <div class="layui-inline" style="">
            <select name="user_type" lay-verify="" >
                <option value="">please select User Type</option>
                <option value="0">Single</option>
                <option value="1">Share</option>
            </select>
        </div>
        <div class="layui-inline" style="width: 150px;">
            <select name="month_user" lay-verify="" >
                <option value="">所有用户</option>
                <option value="1">实际月租用户</option>
                <option value="2">免月租用户</option>
            </select>
        </div>
        <div class="layui-inline" style="padding-left:20px;">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user-search"><i
                    class="iconfont icon-chaxun"></i>Search</button>
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="update_monthly">UpdateMonthLy</button>
            <span style="font-size: 20px;padding-left: 20px;">
                Refresh Time : <span id="up_time" style="color: #FF5722">{$time}</span>
            </span>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="userTable" lay-filter="test"></table>
</div>
<script>
    layui.use(['form', 'table' , 'laydate'], function () {

        //时间插件
        layui.laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });

        var tableIn = layui.table.render({
            elem: '#userTable',
            height: 'full-139',
            cellMinWidth: '80',
            totalRow: true,
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['exports'],
            url: "{:url('index')}?_ajax=1",
            id: 'userTable',
            cols: [[
                { type: 'numbers'},
                { field: 'username', align: 'left', style:'font-weight:bold;' ,width:250, title: 'UserName'},
                { field: 'user_type', title: 'UserType', width:150 ,
                    templet: function (d) {
                        const user_type = d.user_type;
                        if(user_type == 1){
                            return '<font color="red">Share</font>';
                        }else{
                            return 'Single';
                        }
                    }
                },
                { field: 'month_fee', title: 'MonthFee($)', align:"right",
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'card_total', title: 'CardTotal', align:"right",
                    style:'font-weight:bold', totalRow: true},
                { field: 'active', title: 'CardActive', align:"right",
                    style:'font-weight:bold', totalRow: true},
                { field: 'suspended', title: 'CardSuspended', align:"right",
                    style:'font-weight:bold', totalRow: true},
                { field: 'cancel', title: 'CardCancel', align:"right",
                    style:'font-weight:bold', totalRow: true}
            ]],
            page: true,
            limit: 20,
            limits: [20, 100 , 500 ,1000],
        });
        //搜索
        layui.form.on('submit(user-search)', function (data) {
            layui.table.reload('userTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                },
                method:'POST'
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        layui.form.on('submit(update_monthly)', function () {
            var loading =layer.load(1, {shade: [0.1,'#fff']});
            JsPost("{:url('updateMonthly')}",'', function(res){
                layer.close(loading);
                if(res.code >0){
                    $('#up_time').text(res.data.time);
                    layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                        tableIn.reload({
                            page:{
                                curr :1
                            }
                        });
                    });
                }else{
                    layer.msg(res.msg , {time:1500 , icon:2});
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>